package com.itheima.user.controller;

import com.itheima.common.response.ResponseResult;
import com.itheima.common.response.StatusCode;
import com.itheima.common.response.UserOrderVo;
import com.itheima.user.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @作者 itcast
 * @创建日期 2020/10/11 16:20
 **/
@RestController
@RequestMapping("user")
public class UserController {
    @Autowired
    UserService userService;
    @GetMapping("{username}")
    public ResponseResult<UserOrderVo> findUserOrderByUsername(@PathVariable("username") String username){
        try {
            UserOrderVo userOrderVo = userService.findUserOrderVoByUsername(username);
            return ResponseResult.okResult(userOrderVo);
        } catch (Exception e) {
            return ResponseResult.errorResult(StatusCode.SERVER_ERROR);
        }
    }
}
